package com.coocaa.ops.common.tool.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.reflect.MethodSignature;

import java.lang.reflect.Method;
import java.lang.reflect.Type;

/**
 * @author bijiahao
 * @date : 2019/1/16.
 * @description: 切面工具类
 *
 */
public final class AspectUtil {
    /**
     * 获取被切面的方法
     *
     * @param joinPoint
     * @return
     */
    public static Method getMethod(JoinPoint joinPoint) {
        Signature signature = joinPoint.getSignature();
        MethodSignature methodSignature = (MethodSignature) signature;
        Method method = methodSignature.getMethod();
        return method;
    }

    /**
     * 获取被切面的方法返回值类型
     *
     * @param joinPoint
     * @return
     */
    public static Type getReturnType(ProceedingJoinPoint joinPoint) {
        Method method = getMethod(joinPoint);
        Type returnType = method.getGenericReturnType();
        return returnType;
    }
}
